#ifndef _WX_MEDIACTRL_H_
#define _WX_MEDIACTRL_H_





#include "wx/defs.h"





#if wxUSE_MEDIACTRL





#include "wx/control.h"
#include "wx/uri.h"











enum wxMediaState {
  wxMEDIASTATE_STOPPED,
  wxMEDIASTATE_PAUSED,
  wxMEDIASTATE_PLAYING
};

enum wxMediaCtrlPlayerControls {
  wxMEDIACTRLPLAYERCONTROLS_NONE           =   0,

  wxMEDIACTRLPLAYERCONTROLS_STEP           =   1 << 0,

  wxMEDIACTRLPLAYERCONTROLS_VOLUME         =   1 << 1,
  wxMEDIACTRLPLAYERCONTROLS_DEFAULT        =
    wxMEDIACTRLPLAYERCONTROLS_STEP |
    wxMEDIACTRLPLAYERCONTROLS_VOLUME
};

#define wxMEDIABACKEND_DIRECTSHOW   wxT("wxAMMediaBackend")
#define wxMEDIABACKEND_MCI          wxT("wxMCIMediaBackend")
#define wxMEDIABACKEND_QUICKTIME    wxT("wxQTMediaBackend")
#define wxMEDIABACKEND_GSTREAMER    wxT("wxGStreamerMediaBackend")
#define wxMEDIABACKEND_REALPLAYER   wxT("wxRealPlayerMediaBackend")
#define wxMEDIABACKEND_WMP10        wxT("wxWMP10MediaBackend")







class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent {
  public:





    wxMediaEvent( wxEventType commandType = wxEVT_NULL, int winid = 0 )
      : wxNotifyEvent( commandType, winid ) {                                       }






    wxMediaEvent( const wxMediaEvent &clone )
      : wxNotifyEvent( clone ) {                                       }







    virtual wxEvent *Clone() const
    {   return new wxMediaEvent( *this );     }



    DECLARE_DYNAMIC_CLASS( wxMediaEvent )
};







class WXDLLIMPEXP_MEDIA wxMediaCtrl : public wxControl {
  public:
    wxMediaCtrl() : m_imp( NULL ), m_bLoaded( false ) {                                                                   }

    wxMediaCtrl( wxWindow* parent, wxWindowID winid,
                 const wxString& fileName = wxEmptyString,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& szBackend = wxEmptyString,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxT( "mediaCtrl" ) )
      : m_imp( NULL ), m_bLoaded( false ) {
      Create( parent, winid, fileName, pos, size, style,
              szBackend, validator, name );
    }

    wxMediaCtrl( wxWindow* parent, wxWindowID winid,
                 const wxURI& location,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& szBackend = wxEmptyString,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxT( "mediaCtrl" ) )
      : m_imp( NULL ), m_bLoaded( false ) {
      Create( parent, winid, location, pos, size, style,
              szBackend, validator, name );
    }

    virtual ~wxMediaCtrl();

    bool Create( wxWindow* parent, wxWindowID winid,
                 const wxString& fileName = wxEmptyString,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& szBackend = wxEmptyString,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxT( "mediaCtrl" ) );

    bool Create( wxWindow* parent, wxWindowID winid,
                 const wxURI& location,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = 0,
                 const wxString& szBackend = wxEmptyString,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxT( "mediaCtrl" ) );

    bool DoCreate( wxClassInfo* instance,
                   wxWindow* parent, wxWindowID winid,
                   const wxPoint& pos = wxDefaultPosition,
                   const wxSize& size = wxDefaultSize,
                   long style = 0,
                   const wxValidator& validator = wxDefaultValidator,
                   const wxString& name = wxT( "mediaCtrl" ) );

    bool Play();
    bool Pause();
    bool Stop();
    bool Load( const wxString& fileName );
    wxMediaState GetState();
    wxFileOffset Seek( wxFileOffset where, wxSeekMode mode = wxFromStart );
    wxFileOffset Tell();
    wxFileOffset Length();
    double GetPlaybackRate();
    bool SetPlaybackRate( double dRate );
    bool Load( const wxURI& location );
    bool Load( const wxURI& location, const wxURI& proxy );
    wxFileOffset GetDownloadProgress();
    wxFileOffset GetDownloadTotal();
    double GetVolume();
    bool   SetVolume( double dVolume );
    bool    ShowPlayerControls( wxMediaCtrlPlayerControls flags = wxMEDIACTRLPLAYERCONTROLS_DEFAULT );
    bool LoadURI( const wxString& fileName ) {   return Load( wxURI( fileName ) );       }
    bool LoadURIWithProxy( const wxString& fileName, const wxString& proxy ) {   return Load( wxURI( fileName ), wxURI( proxy ) );       }
  protected:
    static wxClassInfo* NextBackend();

    void OnMediaFinished( wxMediaEvent& evt );
    virtual void DoMoveWindow( int x, int y, int w, int h );
    wxSize DoGetBestSize() const;

    #if defined(__WXMAC__) || defined(__WXCOCOA__)
    friend class wxQTMediaBackend;
    #endif
    class wxMediaBackend* m_imp;
    bool m_bLoaded;

    DECLARE_DYNAMIC_CLASS( wxMediaCtrl )
};















class WXDLLIMPEXP_MEDIA wxMediaBackend : public wxObject {
  public:
    wxMediaBackend() {                                   }

    virtual ~wxMediaBackend();

    virtual bool CreateControl( wxControl * ( ctrl ),
                                wxWindow * ( parent ),
                                wxWindowID( winid ),
                                const wxPoint & ( pos ),
                                const wxSize & ( size ),
                                long ( style ),
                                const wxValidator & ( validator ),
                                const wxString & ( name ) ) {   return false;                   }

    virtual bool Play() {   return false;                   }
    virtual bool Pause() {   return false;                   }
    virtual bool Stop() {   return false;                   }

    virtual bool Load( const wxString & ( fileName ) ) {   return false;                   }
    virtual bool Load( const wxURI & ( location ) ) {   return false;                   }

    virtual bool SetPosition( wxLongLong( where ) ) {   return 0;                       }
    virtual wxLongLong GetPosition() {   return 0;                       }
    virtual wxLongLong GetDuration() {   return 0;                       }

    virtual void Move( int ( x ), int ( y ),
                       int ( w ), int ( h ) ) {                                   }
    virtual wxSize GetVideoSize() const
    {   return wxSize( 0, 0 );             }

    virtual double GetPlaybackRate() {   return 0.0;                     }
    virtual bool SetPlaybackRate( double ( dRate ) ) {   return false;                   }

    virtual wxMediaState GetState() {   return wxMEDIASTATE_STOPPED;    }

    virtual double GetVolume() {   return 0.0;                     }
    virtual bool SetVolume( double ( dVolume ) ) {   return false;                   }

    virtual bool Load( const wxURI & ( location ),
                       const wxURI & ( proxy ) ) {   return false;                   }

    virtual bool   ShowPlayerControls(
      wxMediaCtrlPlayerControls( flags ) ) {   return false;                   }
    virtual bool   IsInterfaceShown() {   return false;                   }

    virtual wxLongLong GetDownloadProgress() {    return 0;                      }
    virtual wxLongLong GetDownloadTotal() {    return 0;                      }

    virtual void MacVisibilityChanged() {                                   }
    virtual void RESERVED9() {}

    DECLARE_DYNAMIC_CLASS( wxMediaBackend )
};



#define wxMEDIA_FINISHED_ID    13000
#define wxMEDIA_STOP_ID    13001


DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_FINISHED, wxMEDIA_FINISHED_ID )
DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STOP,     wxMEDIA_STOP_ID )


typedef void ( wxEvtHandler::*wxMediaEventFunction )( wxMediaEvent& );

#define wxMediaEventHandler(func) \
  (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMediaEventFunction, &func)


#define EVT_MEDIA_FINISHED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_FINISHED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
#define EVT_MEDIA_STOP(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STOP, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
#   define wxMEDIA_LOADED_ID      13002
DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_LOADED,     wxMEDIA_LOADED_ID )
#   define EVT_MEDIA_LOADED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_LOADED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
#   define wxMEDIA_STATECHANGED_ID      13003
#   define wxMEDIA_PLAY_ID      13004
#   define wxMEDIA_PAUSE_ID      13005
DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_STATECHANGED,     wxMEDIA_STATECHANGED_ID )
DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PLAY,     wxMEDIA_PLAY_ID )
DECLARE_EXPORTED_EVENT_TYPE( WXDLLIMPEXP_MEDIA, wxEVT_MEDIA_PAUSE,     wxMEDIA_PAUSE_ID )
#   define EVT_MEDIA_STATECHANGED(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_STATECHANGED, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
#   define EVT_MEDIA_PLAY(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PLAY, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),
#   define EVT_MEDIA_PAUSE(winid, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MEDIA_PAUSE, winid, wxID_ANY, wxMediaEventHandler(fn), (wxObject *) NULL ),

class WXDLLIMPEXP_MEDIA wxMediaBackendCommonBase : public wxMediaBackend {
  public:

    void QueueEvent( wxEventType evtType );


    void QueueFinishEvent() {
      QueueEvent( wxEVT_MEDIA_STATECHANGED );
      QueueEvent( wxEVT_MEDIA_FINISHED );
    }


    bool SendStopEvent();


    void QueuePlayEvent();


    void QueuePauseEvent();


    void QueueStopEvent();

  protected:


    void NotifyMovieSizeChanged();


    void NotifyMovieLoaded();


    wxMediaCtrl *m_ctrl;
};




#endif




#endif


